/*

Miranda IM: the free IM client for Microsoft* Windows*

Copyright 2000-2007 Miranda ICQ/IM project, 
all portions of this codebase are copyrighted to the people 
listed in contributors.txt.

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or ( at your option ) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
aLONG with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

*/

/**
 * System Includes:
 **/
#include "commonheaders.h"

static IDSTRLIST Languages[]={
   { 0, LPGENT( "Unspecified" ), 0},
   {55, LPGENT( "Afrikaans" ), 0},
   {58, LPGENT( "Albanian" ), 0},
   { 1, LPGENT( "Arabic" ), 0},
   {59, LPGENT( "Armenian" ), 0},
   {68, LPGENT( "Azerbaijani" ), 0},
   {72, LPGENT( "Belorussian" ), 0},
   { 2, LPGENT( "Bhojpuri" ), 0},
   {56, LPGENT( "Bosnian" ), 0},
   { 3, LPGENT( "Bulgarian" ), 0},
   { 4, LPGENT( "Burmese" ), 0},
   { 5, LPGENT( "Cantonese" ), 0},
   { 6, LPGENT( "Catalan" ), 0},
   {61, LPGENT( "Chamorro" ), 0},
   { 7, LPGENT( "Chinese" ), 0},
   { 8, LPGENT( "Croatian" ), 0},
   { 9, LPGENT( "Czech" ), 0},
   {10, LPGENT( "Danish" ), 0},
   {11, LPGENT( "Dutch" ), 0},
   {12, LPGENT( "English" ), 0},
   {13, LPGENT( "Esperanto" ), 0},
   {14, LPGENT( "Estonian" ), 0},
   {15, LPGENT( "Farci" ), 0},
   {16, LPGENT( "Finnish" ), 0},
   {17, LPGENT( "French" ), 0},
   {18, LPGENT( "Gaelic" ), 0},
   {19, LPGENT( "German" ), 0},
   {20, LPGENT( "Greek" ), 0},
   {70, LPGENT( "Gujarati" ), 0},
   {21, LPGENT( "Hebrew" ), 0},
   {22, LPGENT( "Hindi" ), 0},
   {23, LPGENT( "Hungarian" ), 0},
   {24, LPGENT( "Icelandic" ), 0},
   {25, LPGENT( "Indonesian" ), 0},
   {26, LPGENT( "Italian" ), 0},
   {27, LPGENT( "Japanese" ), 0},
   {28, LPGENT( "Khmer" ), 0},
   {29, LPGENT( "Korean" ), 0},
   {69, LPGENT( "Kurdish" ), 0},
   {30, LPGENT( "Lao" ), 0},
   {31, LPGENT( "Latvian" ), 0},
   {32, LPGENT( "Lithuanian" ), 0},
   {65, LPGENT( "Macedonian" ), 0},
   {33, LPGENT( "Malay" ), 0},
   {63, LPGENT( "Mandarin" ), 0},
   {62, LPGENT( "Mongolian" ), 0},
   {34, LPGENT( "Norwegian" ), 0},
   {57, LPGENT( "Persian" ), 0},
   {35, LPGENT( "Polish" ), 0},
   {36, LPGENT( "Portuguese" ), 0},
   {60, LPGENT( "Punjabi" ), 0},
   {37, LPGENT( "Romanian" ), 0},
   {38, LPGENT( "Russian" ), 0},
   {39, LPGENT( "Serbo-Croatian" ), 0},
   {66, LPGENT( "Sindhi" ), 0},
   {40, LPGENT( "Slovak" ), 0},
   {41, LPGENT( "Slovenian" ), 0},
   {42, LPGENT( "Somali" ), 0},
   {43, LPGENT( "Spanish" ), 0},
   {44, LPGENT( "Swahili" ), 0},
   {45, LPGENT( "Swedish" ), 0},
   {46, LPGENT( "Tagalog" ), 0},
   {64, LPGENT( "Taiwaness" ), 0},
   {71, LPGENT( "Tamil" ), 0},
   {47, LPGENT( "Tatar" ), 0},
   {48, LPGENT( "Thai" ), 0},
   {49, LPGENT( "Turkish" ), 0},
   {50, LPGENT( "Ukrainian" ), 0},
   {51, LPGENT( "Urdu" ), 0},
   {52, LPGENT( "Vietnamese" ), 0},
   {67, LPGENT( "Welsh" ), 0},
   {53, LPGENT( "Yiddish" ), 0},
   {54, LPGENT( "Yoruba" ), 0},
};

static IDSTRLIST occupations[] = {
   { 0, LPGENT( "Unspecified" ), 0},
   { 1, LPGENT( "Academic" ), 0},
   { 2, LPGENT( "Administrative" ), 0},
   { 3, LPGENT( "Art/Entertainment" ), 0},
   { 4, LPGENT( "College Student" ), 0},
   { 5, LPGENT( "Computers" ), 0},
   { 6, LPGENT( "Community & Social" ), 0},
   { 7, LPGENT( "Education" ), 0},
   { 8, LPGENT( "Engineering" ), 0},
   { 9, LPGENT( "Financial Services" ), 0},
   {10, LPGENT( "Government" ), 0},
   {11, LPGENT( "High School Student" ), 0},
   {12, LPGENT( "Home" ), 0},
   {13, LPGENT( "ICQ - Providing Help" ), 0},
   {14, LPGENT( "Law" ), 0},
   {15, LPGENT( "Managerial" ), 0},
   {16, LPGENT( "Manufacturing" ), 0},
   {17, LPGENT( "Medical/Health" ), 0},
   {18, LPGENT( "Military" ), 0},
   {19, LPGENT( "Non-Government Organization" ), 0},
   {20, LPGENT( "Professional" ), 0},
   {21, LPGENT( "Retail" ), 0},
   {22, LPGENT( "Retired" ), 0},
   {23, LPGENT( "Science & Research" ), 0},
   {24, LPGENT( "Sports" ), 0},
   {25, LPGENT( "Technical" ), 0},
   {26, LPGENT( "University Student" ), 0},
   {27, LPGENT( "Web Building" ), 0},
   {99, LPGENT( "Other Services" ), 0}
};

static IDSTRLIST Interests[] = {
   {  0, LPGENT( "Unspecified" ), 0},
   {100, LPGENT( "Art" ), 0},
   {101, LPGENT( "Cars" ), 0},
   {102, LPGENT( "Celebrity Fans" ), 0},
   {103, LPGENT( "Collections" ), 0},
   {104, LPGENT( "Computers" ), 0},
   {105, LPGENT( "Culture & Literature" ), 0},
   {106, LPGENT( "Fitness" ), 0},
   {107, LPGENT( "Games" ), 0},
   {108, LPGENT( "Hobbies" ), 0},
   {109, LPGENT( "ICQ - Providing Help" ), 0},
   {110, LPGENT( "Internet" ), 0},
   {111, LPGENT( "Lifestyle" ), 0},
   {112, LPGENT( "Movies/TV" ), 0},
   {113, LPGENT( "Music" ), 0},
   {114, LPGENT( "Outdoor Activities" ), 0},
   {115, LPGENT( "Parenting" ), 0},
   {116, LPGENT( "Pets/Animals" ), 0},
   {117, LPGENT( "Religion" ), 0},
   {118, LPGENT( "Science/Technology" ), 0},
   {119, LPGENT( "Skills" ), 0},
   {120, LPGENT( "Sports" ), 0},
   {121, LPGENT( "Web Design" ), 0},
   {122, LPGENT( "Nature and Environment" ), 0},
   {123, LPGENT( "News & Media" ), 0},
   {124, LPGENT( "Government" ), 0},
   {125, LPGENT( "Business & Economy" ), 0},
   {126, LPGENT( "Mystics" ), 0},
   {127, LPGENT( "Travel" ), 0},
   {128, LPGENT( "Astronomy" ), 0},
   {129, LPGENT( "Space" ), 0},
   {130, LPGENT( "Clothing" ), 0},
   {131, LPGENT( "Parties" ), 0},
   {132, LPGENT( "Women" ), 0},
   {133, LPGENT( "Social science" ), 0},
   {134, LPGENT( "60's" ), 0},
   {135, LPGENT( "70's" ), 0},
   {136, LPGENT( "80's" ), 0},
   {137, LPGENT( "50's" ), 0},
   {138, LPGENT( "Finance and corporate" ), 0},
   {139, LPGENT( "Entertainment" ), 0},
   {140, LPGENT( "Consumer electronics" ), 0},
   {141, LPGENT( "Retail stores" ), 0},
   {142, LPGENT( "Health and beauty" ), 0},
   {143, LPGENT( "Media" ), 0},
   {144, LPGENT( "Household products" ), 0},
   {145, LPGENT( "Mail order catalog" ), 0},
   {146, LPGENT( "Business services" ), 0},
   {147, LPGENT( "Audio and visual" ), 0},
   {148, LPGENT( "Sporting and athletic" ), 0},
   {149, LPGENT( "Publishing" ), 0},
   {150, LPGENT( "Home automation" ), 0}
};

static IDSTRLIST Past[] = {
   {  0, LPGENT( "Unspecified" ), 0},
   {300, LPGENT( "Elementary School" ), 0},
   {301, LPGENT( "High School" ), 0},
   {302, LPGENT( "College" ), 0},
   {303, LPGENT( "University" ), 0},
   {304, LPGENT( "Military" ), 0},
   {305, LPGENT( "Past Work Place" ), 0},
   {306, LPGENT( "Past Organization" ), 0},
   {399, LPGENT( "Other" ), 0}
};

static IDSTRLIST Affiliations[] = {
   {  0, LPGENT( "Unspecified" ), 0},
   {200, LPGENT( "Alumni Org." ), 0},
   {201, LPGENT( "Charity Org." ), 0},
   {202, LPGENT( "Club/Social Org." ), 0},
   {203, LPGENT( "Community Org." ), 0},
   {204, LPGENT( "Cultural Org." ), 0},
   {205, LPGENT( "Fan Clubs" ), 0},
   {206, LPGENT( "Fraternity/Sorority" ), 0},
   {207, LPGENT( "Hobbyists Org." ), 0},
   {208, LPGENT( "International Org." ), 0},
   {209, LPGENT( "Nature and Environment Org." ), 0},
   {210, LPGENT( "Professional Org." ), 0},
   {211, LPGENT( "Scientific/Technical Org." ), 0},
   {212, LPGENT( "Self Improvement Group" ), 0},
   {213, LPGENT( "Spiritual/Religious Org." ), 0},
   {214, LPGENT( "Sports Org." ), 0},
   {215, LPGENT( "Support Org." ), 0},
   {216, LPGENT( "Trade and Business Org." ), 0},
   {217, LPGENT( "Union" ), 0},
   {218, LPGENT( "Volunteer Org." ), 0},
   {299, LPGENT( "Other" ), 0},
};

static IDSTRLIST Marital[]={
   { 0, LPGENT( "Unspecified" ), 0},
   {10, LPGENT( "Single" ), 0},
   {11, LPGENT( "Close relationships" ), 0},
   {12, LPGENT( "Engaged" ), 0},
   {20, LPGENT( "Married" ), 0},
   {30, LPGENT( "Divorced" ), 0},
   {31, LPGENT( "Separated" ), 0},
   {40, LPGENT( "Widowed" ), 0}
};

static IDSTRLIST Prefixes[]={
   {  0, LPGENT( "Unspecified" ), 0},
   {'j', LPGENT( "jun." ), 0},
   {'s', LPGENT( "sen." ), 0}
};

/**
 * name:	IDStringList_Translate
 * desc:	translates the text of each item of an IDStrinList to users locale
 *			language and saves result in szTranslated member for later use and 
 *			faster access to translated strings later.
 * param:	pList		- pointer to list to translate
 *			nListCount	- number of list items
 *
 * return:	nothing
 **/
static VOID IDStringList_Translate( LPIDSTRLIST pList, UINT nListCount )
{
	while( 0 < nListCount-- )	
		pList[nListCount].ptszTranslated = TranslateTS( pList[nListCount].szText );
}

static IDSTRLIST *MyCountries = NULL;
static int MyCountriesCount = 0;

INT GetCountryList( WPARAM wParam, LPARAM lParam )
{
	if( MyCountries == NULL ) {
		struct CountryListEntry *country;

		if( CallService( MS_UTILS_GETCOUNTRYLIST, ( WPARAM )&MyCountriesCount, ( LPARAM )&country ) )
			return 1;

		MyCountries = ( IDSTRLIST* )mir_alloc( MyCountriesCount * sizeof( IDSTRLIST ) );
		if( MyCountries == NULL ) 
			return 1;

		for( int i = 0; i < MyCountriesCount; i++ ) {
			MyCountries[i].nID = country[i].id;
			MyCountries[i].szText = mir_utf8decodeT( country[i].szName );
			MyCountries[i].ptszTranslated = TranslateTS( MyCountries[i].szText );
		}
	}
	*( LPUINT )wParam = MyCountriesCount;
	*( LPIDSTRLIST* )lParam = MyCountries;
	return 0;
}

INT GetMaritalList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Marital )/sizeof( Marital[0] );
	*( LPIDSTRLIST* )lParam = Marital;
	if( !Marital[0].ptszTranslated )
		IDStringList_Translate( Marital, *( LPUINT )wParam );
	return 0;
}

INT GetLanguageList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Languages )/sizeof( Languages[0] );
	*( LPIDSTRLIST* )lParam = Languages;
	if( !Languages[0].ptszTranslated )
		IDStringList_Translate( Languages, *( LPUINT )wParam );
	return 0;
}

INT GetOccupationList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( occupations )/sizeof( occupations[0] );
	*( LPIDSTRLIST* )lParam = occupations;
	if( !occupations[0].ptszTranslated )
		IDStringList_Translate( occupations, *( LPUINT )wParam );
	return 0;
}

INT GetInterestsList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Interests )/sizeof( Interests[0] );
	*( LPIDSTRLIST* )lParam = Interests;
	if( !Interests[0].ptszTranslated )
		IDStringList_Translate( Interests, *( LPUINT )wParam );
	return 0;
}

INT GetPastList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Past )/sizeof( Past[0] );
	*( LPIDSTRLIST* )lParam = Past;
	if( !Past[0].ptszTranslated )
		IDStringList_Translate( Past, *( LPUINT )wParam );
	return 0;
}

INT GetAffiliationsList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Affiliations )/sizeof( Affiliations[0] );
	*( LPIDSTRLIST* )lParam = Affiliations;
	if( !Affiliations[0].ptszTranslated )
		IDStringList_Translate( Affiliations, *( LPUINT )wParam );
	return 0;
}

INT GetNamePrefixList( WPARAM wParam, LPARAM lParam )
{
	*( LPUINT )wParam = sizeof( Prefixes )/sizeof( Prefixes[0] );
	*( LPIDSTRLIST* )lParam = Prefixes;
	if( !Prefixes[0].ptszTranslated )
		IDStringList_Translate( Prefixes, *( LPUINT )wParam );
	return 0;
}

VOID Constants_LoadModule( VOID )
{
	/*
	CreateServiceFunction( MS_USERINFO_GETLIST_MARITALSTATUS, GetMaritalList );
	CreateServiceFunction( MS_USERINFO_GETLIST_LANGUAGES, GetLanguageList );
	CreateServiceFunction( MS_USERINFO_GETLIST_TIMEZONES, GetTimezoneList );
	CreateServiceFunction( MS_USERINFO_GETLIST_COUNTRIES, GetCountryList );
	CreateServiceFunction( MS_USERINFO_GETLIST_OCCUPATIONS, GetOccupationList );
	CreateServiceFunction( MS_USERINFO_GETLIST_intERESTCATS, GetInterestsList );
	CreateServiceFunction( MS_USERINFO_GETLIST_PASTCATS, GetPastList );
	CreateServiceFunction( MS_USERINFO_GETLIST_AFFILIATIONSCATS, GetAffiliationsList );
	CreateServiceFunction( MS_USERINFO_GETLIST_NAMEPREFIXES, GetNamePrefixList );
	*/
}

VOID Constants_UnloadModule( VOID )
{
	if( MyCountries ) {
		for( int i = 0; i < MyCountriesCount; i++ )
			mir_free( ( PVOID )MyCountries[i].szText );
		mir_free( MyCountries );
	}
}